/**
 * Created by 冠东 on 2017/10/24.
 */
mainApp.factory("attendanceFactory",function(){
    var service={};
    //获取全部列表
    service.getListData=function(currentindex){
        var obj={
            "pageIndex": currentindex,
            "pageSize": 8
        }
        var list = "";
        RequestUtils.postJson('../am/get',obj).done(function (resp) {
            console.log(resp);
            if(resp.resultCode==0){
                console.log(resp.data);
                list=resp.data;
            }else{
                CommonUtils.buildFailHint('列表', '获取失败');
            }

        });

        return list;
    };

    service.getAttendData=function(id,month){
        console.log(id,month);
        var list = "";
        $.ajax({
            url: '../am/getAttendByMonth/'+id+'/'+month,
            type: 'GET',
            async: 'true',
            cache: 'no-cache',
            dataType: 'json',
            async: false,//同步
            success: function (result) {

                if(result.resultCode=='0'){
                    list=result.data;
                }else {
                    CommonUtils.buildFailHint('列表', '获取失败');
                }
            }

        })
        return list;
    };

    return service;
})


mainApp.controller("attendController",function($scope,$http,attendanceFactory){
    //一开始进页面
    $scope.listData=attendanceFactory.getListData(1);
    //获取list
    $scope.list=$scope.listData.items;


    //翻页
    $scope.NextListData=function(pageIndex){

        $scope.listData=attendanceFactory.getListData(pageIndex);
        $scope.list=$scope.listData.items;

    }

    //打开模态框
    $scope.openAttendDataModal=function(id,month){

        var AttendData=attendanceFactory.getAttendData(id,month);
        //填充列表数字
        var myChart = echarts.init(document.getElementById('main'));
        var obj2={
            data:[

            ]
        };
        for (var i = 0; i < AttendData.length; i++) {
            var data={value:AttendData[i].counts,name:AttendConst[AttendData[i].status]};
            obj2.data.push(data);
        }

        var option=CommonUtils.getAttendOption(obj2,AttendStatusData,'考勤记录');
        // 使用刚指定的配置项和数据显示图表。
        myChart.setOption(option);

        $("#AttendDataModal").modal("show");

    }

    $scope.openSelectAttendModal=function(){
        $("#selectAttendModal").modal("hide");
    }
    CommonUtils.setDatetimepicker("selectAttendDateTime");


})

